package entity;

import com.alibaba.fastjson.JSONObject;

import org.apache.poi.ss.formula.functions.T;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wuzhao on 2017/8/1 0001.
 */
public class xxx {

    public static <T,O> T origToTarget(O orig,Class<T> targetClass){
        T vo = null;
        try {
            String jsonString = JSONObject.toJSONString(orig);
            vo = JSONObject.parseObject(jsonString, targetClass);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return vo;
    }

    public static <O,T> List<T> origListToTargetsList(List<O> origList, Class<T> tClazz){
        if (origList == null || origList.size() == 0 || tClazz ==null)
            return null;
        List<T> tList = new ArrayList<T>();
        for (O orig:origList){
            T t = origToTarget(orig, tClazz);
            tList.add(t);
        }
        return tList;
    }

    public static <O,T> List<T> origListToTargets(List<O> origList, Class<T> tClazz){
        if (origList == null || origList.size() == 0 || tClazz ==null)
            return null;
        List<T> tList = new ArrayList<T>();
        for (O orig:origList){
            T t = origToTarget(orig, tClazz);
            tList.add(t);
        }
        return tList;
    }

    public static <O extends BaseEntity> List<O> addAll(List<O> origList){

        return origList;
    }

    public static void main(String[] args) {
        List<Users> use = new ArrayList<Users>();
        List<Users> o = addAll(use);
        List<Cat> cat = new ArrayList<Cat>();
        List<Cat> users = addAll(cat);
    }
}
